#include "task_queue.h"

int task_queue_init(task_queue_t*pqueue){
    bzero(pqueue,sizeof(task_queue_t));
    return 0;
}
int en_queue(task_queue_t*pqueue,int netfd){
    node_t* newNode=(node_t*)calloc(1,sizeof(node_t));
    newNode->netfd=netfd;
    if(pqueue->size==0){
        pqueue->front=newNode;
        pqueue->rear=newNode;
    }else{
        pqueue->rear->next=newNode;
        pqueue->rear=newNode;
    }
    pqueue->size++;
    return 0;
}
int de_queue(task_queue_t*pqueue){
    node_t*cur=pqueue->front;
    if(pqueue->size==1){
        pqueue->front=NULL;
        pqueue->rear=NULL;
    }else{
        pqueue->front=pqueue->front->next;
    }
    pqueue->size--;
    free(cur);
    return 0;
}
int print_queue(task_queue_t*pqueue){
    node_t*cur=pqueue->front;
    while(cur){
        printf("%3d",cur->netfd);
        cur=cur->next;
    }
    printf("\n");
    return 0;
}

